#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/18 18:24
# @Author : 闫峰
# @File    : test19590.py
from common.setting import ensure_path_sep
from utils.logging_tool.init_logger import init_logger
from utils.mysqlUtils.db_pool import Database
from utils.mysqlUtils.mongodb_utils import MongoDBLink

INFO, ERROR, WARNING = init_logger()


class Test:
    """
    敏感词调度任务
    """

    modb = MongoDBLink(uri='mongodb://reader:33oQm3o6nA9HaLhW#@139.159.193.165:8635,121.37.18.161:8635/?authSource=admin',
                       dbname='zhcxkj_riskworker', coll_name='Walmart_Listing_Sensitive')

    mysql_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "test_jdw_database")



    def test(self,source_id,sku,strategy_id):

        get_group_sku_list = """
        select group_sku from  test_zhcxkj_center_product.rb_product_group_sku rpgs where rpgs.sku =%s;
        """
        sku_set = set()
        group_sku_list = self.mysql_db.fetch_all_tuple(get_group_sku_list,(sku,))
        if not len(group_sku_list):
            sku_set.add(sku)
        sku_set |= set(map(lambda x:x[0],group_sku_list))
        sku_set.add(sku)

        get_source_sku_list = """
        select 
            twwl.item_id 
            from  test_zhcxkj_center_listing_comprehensive.t_walmart_wfs_listing twwl 
            join test_zhcxkj_center_listing_comprehensive.t_walmart_quantity rp on twwl.customer_id =rp.customer_id and twwl.source_sku=rp.source_sku
        where twwl.source_id= %s
        and twwl.status =1
        and twwl.sku in %s
        and twwl.fulfillment_type !='Walmart Fulfilled'
        and twwl.is_deleted =0
        """
        source_item_id_list = self.mysql_db.fetch_all_tuple(get_source_sku_list,(source_id,sku_set))
        if not len(source_item_id_list):
            pass
        item_id_list = set(map(lambda x:x[0],source_item_id_list))
        print()
        get_actual_item_id_list = """
         select item_id from test_zhcxkj_center_strategy_comprehensive.t_walmart_replenishment_queue_detail
        where queue_id = (select id from test_zhcxkj_center_strategy_comprehensive.t_walmart_strategy_queue where strategy_id=%s order by id desc limit 1)
        """
        actual_item_id_list = self.mysql_db.fetch_all_tuple(get_actual_item_id_list,(strategy_id,))
        actual_item_id_set = set(map(lambda x:x[0],actual_item_id_list))
        if item_id_list != actual_item_id_set:
            print(f"测试不通过")
        print(f"测试通过")


if __name__ == '__main__':
    Test().test(12564,"1955804",19)